# import os
# import requests
# from bs4 import BeautifulSoup #
# re = os.path.dirname(os.path.abspath(__file__))
# print(re)
# path = os.path.join(re,'img')
# res = requests.get('http://pic.yesky.com/c/6_20491_1.shtml')
# soup = BeautifulSoup(res.text,'html.parser')
# jb = soup.find('ul',class_='classification_listContent')
# # print(jb.text)
# i = jb.find_all('li')
# for dl in i:
#     img = dl.find('img')
#     img_src = img.get('src')
#     img_response = requests.get(img_src)
#     path1 = os.path.join(path,img_src.rsplit('/',1)[-1])
#     with open(path1,'wb') as f:
#         f.write(img_response.content)

import os
import requests
from bs4 import BeautifulSoup
re = os.path.dirname(os.path.abspath(__file__))
print(re)
path0 = "D:/天极"
img_path = os.path.join(path0, 'img')
res = requests.get('http://pic.yesky.com/c/6_20491_1.shtml')
soup = BeautifulSoup(res.text, 'html.parser')
jb = soup.find('ul', class_='classification_listContent')
i = jb.find_all('li')
for dl in i:
    img = dl.find('img')
    if img is not None:
        img_src = img.get('src')
        img_response = requests.get(img_src)
        file_name = img_src.rsplit('/', 1)[-1]
        path1 = os.path.join(img_path, file_name)
        with open(path1, 'wb') as f:
            f.write(img_response.content)



# import os
# import requests
# from bs4 import BeautifulSoup
# base_path = os.path.dirname(os.path.abspath(__file__))
# img_path = os.path.join(base_path, 'img')
# response = requests.get('http://pic.yesky.com/c/6_20491_1.shtml')
# soup = BeautifulSoup(response.text, 'html.parser')
# div_obj = soup.find(name='div', attrs={'class': 'lb_box'})
# list_dd = div_obj.find_all(name='dd')
# for dd in list_dd:
#     a_obj = dd.find('a')
#     dir_path = os.path.join(img_path, a_obj.text)
#     if not os.path.isdir(dir_path):
#         os.mkdir(dir_path)
#     a_response = requests.get(a_obj.get('href'))
#     a_response.encoding = 'GBK'
#     soup2 = BeautifulSoup(a_response.text, 'html.parser')
#     div_obj2 = soup2.find(name='div', attrs={'class': 'overview'})
#     img_list = div_obj2.find_all(name='img')
#     for img in img_list:
#         img_src = img.get('src')
#         img_response = requests.get(img_src)
#         file_path = os.path.join(dir_path, img_src.rsplit('/', 1)[-1])
#         with open(file_path, 'wb') as f:
#             f.write(img_response.content)
